import requests
import redis

def get_url():
    client = redis.Redis(host='localhost', port=6379, db=0)
    url = client.lpop("requested_url")
    client.close()
    return url.decode()

def add_url(url):
    client = redis.Redis(host='localhost', port=6379, db=0)
    client.lpush("requested_url", url)
    client.close()


def main():
    for i in range(10):
        try:
            url = get_url()
            response = requests.get(url, timeout=1)
            print(response.status_code)
        except Exception as e:
            add_url(url)
            print(f'请求{url}发生错误{e}')
main()